<?php
$this->headLink()
->appendStylesheet($this->Css('button.css'));
$this->headScript()
->appendFile($this->js('plugins/jquery.clockpick.1.2.7.min.js'))
->appendFile($this->js('jquery-validate/lib/jquery.metadata.js'))
->appendFile($this->js('jquery-validate/jquery.validate.min.js'))
->captureStart()?>
$(document).ready(function(){
	$(".time_select").clockpick({
	starthour : 6,
	endhour : 20,
	minutedivisions: 12,
	military :true
	});

	$(".delbtn").click(function(){
		var sn = $(this).attr('id').substr(2);

		$.getJSON('<?php echo $this->route('delete')?>',{sn:sn},function(data){
			if (data==true) {
				$("#tr-"+sn).remove();
			}
			else {
				alert ('<?php echo $this->translate('Because it has set the course schedule, can not delete the section set')?>');
			}
		});
	});

	$("#addBtn").click(function(){
		$("#setForm").validate({
		messages:{
			n_sort:{required: '<?php echo $this->translate('This field is required.')?>'},
			n_time_start:{required: '<?php echo $this->translate('This field is required.')?>'},
			n_time_end:{required: '<?php echo $this->translate('This field is required.')?>'},
			n_section:{required: '<?php echo $this->translate('This field is required.')?>'}
		}
		});
		$("#setForm").attr('action','<?php echo $this->route('add')?>').submit();
	});

});
<?php $this->headScript()->captureEnd()?>
<style>
<!--
.delbtn {cursor:pointer}
#listTable{margin:5px; border:thin #ccc solid; padding:3px}
.error{color:red}
-->
</style>
<h1><?php echo $this->translate('section set')?></h1>
<form action="" method="post" id="setForm" >
<select name="year_semester" class="refresh" id="year_semester"  onChange="this.form.submit()">
<?php echo  $this->YearSemesterOptions($this->year_semester) ?>
</select>

<label for="sel_grade" ><?php echo $this->translate('choise grade')?> : </label>
<select name="sel_grade" id="sel_grade" validate="required:true"   onChange="this.form.submit()">
<?php echo $this->ClassGradeOptions($this->grade)?>
</select>

<label for="sameset"><?php echo $this->translate('same set')?></label>
<input type="checkbox" name="sameset" id="sameset"  value="1" />
<input type="submit"  name="act"  value="<?php echo $this->translate('save')?>" />

<table id="listTable">
<thead>
<tr>
<th><?php echo $this->translate('sort') ?></th>
<th><?php echo $this->translate('common') ?></th>
<th><?php echo $this->translate('time_start') ?></th>
<th><?php echo $this->translate('time_end') ?></th>
<th><?php echo $this->translate('section') ?></th>
<td></td>
</tr>
</thead>
<tbody>
<?php foreach ($this->data as $val):?>
<tr id="tr-<?php echo $val['sn']?>">
<td><input type="text" name="sort[<?php echo $val['sn']?>]" value="<?php echo $val['sort']?>" size="3"/></td>
<td>
<input type="checkbox"  name="common[<?php echo $val['sn']?>]"  value="Y"  <?php if($val['common']=='Y'):?>checked="checked"<?php endif?> />
</td>
<td><input type="text"  class="time_select" name="time_start[<?php echo $val['sn']?>]" value="<?php echo $val['time_start']?>" size="6"/></td>
<td><input type="text"  class="time_select" name="time_end[<?php echo $val['sn']?>]" value="<?php echo $val['time_end']?>" size="6"/></td>
<td><input type="text"  name="section[<?php echo $val['sn']?>]"  value="<?php echo $val['section']?>"  size="10"/></td>
<td><span class="ui-state-default ui-corner-all ui-icon ui-icon-trash delbtn" id="d-<?php echo $val['sn']?>" title="<?php echo $this->translate('Delete section')?>"></span></td>
</tr>
<?php endforeach?>
<tr>
<td><input type="text"  id="n_sort" name="n_sort"  value="" size="3" class="required" /></td>
<td><input type="checkbox"  id="n_common" name="n_common"  value="Y"  /></td>
<td><input type="text"  class="time_select required"  id="n_time_start"  name="n_time_start" value="" size="6" /></td>
<td><input type="text"  class="time_select required" id="n_time_end" name="n_time_end"  value="" size="6" /></td>
<td><input type="text"  name="n_section"  id="n_section" value=""  size="10" class="required"/></td>
<td>
<a id="addBtn" class="fg-button ui-state-default fg-button-icon-left ui-corner-all" >
<span class="ui-icon ui-icon-plus" ></span>
<?php echo $this->translate('append')?>
</a>
</td>
</tr>
</tbody>
</table>
</form>
